package com.myBlog.controller;


import com.myBlog.constants.SystemConstants;
import com.myBlog.domain.ResponseResult;
import com.myBlog.domain.dto.AddCommentDTO;
import com.myBlog.domain.entity.Comment;
import com.myBlog.service.CommentService;
import com.myBlog.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/comment")
@Api(tags = "评论", description = "评论相关接口")
public class CommentController {
    @Resource
    private CommentService commentService;

    /**
     * 条件分页查询评论
     * @param articleId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/commentList")
    public ResponseResult commentList(Long articleId, Integer pageNum, Integer pageSize) {
        return commentService.commentList(SystemConstants.ARTICLE_COMMENT, articleId, pageNum, pageSize);
    }

    /**
     * 添加评论
     * @param addCommentDTO
     * @return
     */
    @PostMapping("/addComment")
    public ResponseResult addComment(@RequestBody AddCommentDTO addCommentDTO) {
        Comment comment = BeanCopyUtils.copyBean(addCommentDTO, Comment.class);
        return commentService.addComment(comment);
    }

    /**
     * 友链评论
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("linkCommentList")
    public ResponseResult linkCommentList(Integer pageNum, Integer pageSize) {
        return commentService.commentList(SystemConstants.LINK_COMMENT, null, pageNum, pageSize);
    }

}
